//导入axios
import axios from 'axios';
let http = axios.create();

http.interceptors.request.use(
    config => {
        config.withcredentials = true;  //允许携带token
        //从sessionstorage获取token
        let sessionstorage = window.sessionStorage;
        const token = sessionstorage.getItem("token");
        if (token) {
            config.headers.token = token  //请求头加上token
        }
        return config
    }
);
http.interceptors.response.use(
    response => {
        let token = response.headers.token;
        // console.log(token + "..............");
        if (token) {
            //将token放到sessionstorage中
            let sessionstorage = window.sessionStorage;
            sessionstorage.setItem("token", token);
        }
        return response;
    }
);
//导出
export default http